<?php
/**
 * Ecart
 * 
 * This file is part of Ecart.
 * 
 * Ecart is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Ecart is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Ecart.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category    Ecart
 * @package     Ecart_Cms
 * @copyright   Copyright 2008-2009 E-Cart LLC
 * @license     GNU Public License V3.0
 */

/**
 *
 * @category    Ecart
 * @package     Ecart_Cms
 * @subpackage  Ecart_Cms_Model
 * @author      Ecart Core Team <core@ecartcommerce.com>
 */
class Ecart_Cms_Model_Form_Comment extends Ecart_Form
{
    protected $_translatorModule = 'account';
    
    public function __construct($options = null)
    {
        $page = $options['pageId'];
        unset($options['pageId']);
        $default = array(
            'id' => 'form-page-comment',
            'action' => Zend_Controller_Front::getInstance()->getBaseUrl()
                 . Ecart_Locale::getLanguageUrl() 
                 . '/cms/comment/add/page/'
                 . $page . '#form-page-comment'
        );
        if (is_array($options)) {
            $default = array_merge($default, $options);
        }
        
        parent::__construct($default);
        $customer = Ecart::single('account/customer')
            ->find(Ecart::getCustomerId())->current();
        if ($customer) {
            $name = $customer->firstname . ' ' . $customer->lastname;
            $email = $customer->email;
            $name = $name ? $name : '';
            $email = $email ? $email : '';
        } else {
            $name = 'Guest';
            $email = '';
        }
        
        $this->addElement('hidden', 'page', array(
            'value' => $page
        ));
        $this->addElement('text', 'author', array(
            'required' => true,
            'label' => 'Name',
            'value' => $name,
            'class' => 'input-text required'
        ));
        $this->addElement('text', 'email', array(
            'required' => true,
            'label' => 'Email address',
            'value' => $email,
            'class' => 'input-text required',
            'validators' => array(
                new Zend_Validate_EmailAddress()
            )
        ));
        $this->addElement('textarea', 'content', array(
            'required' => true,
            'label' => 'Comment',
            'class' => 'input-text required',
            'rows' => '7',
            'cols' => '50'
        ));
        
        $this->addDisplayGroup(array('author', 'email', 'content'), 'comment');
        
        $this->getDisplayGroup('comment')
            ->addRow(array('author', 'email'), 'row1')
            ->addRow('content', 'row2');
            
        $this->getDisplayGroup('comment')->getRow('row1')
            ->addColumn('author', 'col1')
            ->addColumn('email', 'col2');
            
        $this->addElement('button', 'submit', array(
            'type' => 'submit',
            'class' => 'button',
            'label' => 'Save'
        ));
        
        $this->addActionBar(array('submit'));
    }
}